package com.ft.oa.service.customer.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ft.oa.domain.customer.Customer;
import com.ft.oa.domain.customer.CustomerOrganiza;
import com.ft.oa.mapper.customer.CustomerMapper;
import com.ft.oa.mapper.customer.CustomerOrganizaMapper;
import com.ft.oa.service.customer.CustomerOrganizaService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 公司组织架构
 */
@Service
public class CustomerOrganizaServiceImpl implements CustomerOrganizaService {

    @Resource
    private CustomerOrganizaMapper customerOrganizaMapper;

    @Resource
    private CustomerMapper customerMapper;


    /**
     * 查询组织架构
     *
     * @param
     * @return
     */
    @Override
    public List<CustomerOrganiza> list(CustomerOrganiza customerOrganiza) {
        QueryWrapper<CustomerOrganiza> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("customer_id",customerOrganiza.getCustomerId());
        List<CustomerOrganiza> customerOrganizas = customerOrganizaMapper.selectList(queryWrapper);
        return customerOrganizas;
    }

    /**
     * 添加组织架构
     *
     * @param customerOrganiza
     * @return
     */
    @Override
    public int insert(CustomerOrganiza customerOrganiza) {
        Customer customer = customerMapper.selectById(customerOrganiza.getCustomerId());
        int count = customer.getHeadCount();
       if (customerOrganiza !=null){
           int insert = customerOrganizaMapper.insert(customerOrganiza);
           if (insert>=1){
               count++;
               customer.setHeadCount(count);
               customerMapper.updateById(customer);
           }
           return insert;
       }else {
           return 0;
       }
    }

    /**
     * 查询部门下人员信息
     *
     * @param customerOrganiza
     * @return
     */
    @Override
    public Map<String, Object> select(CustomerOrganiza customerOrganiza) {

        HashMap<String, Object> hashMap = new HashMap<>();

        for (int i = 1;i<=8;i++){
            QueryWrapper<CustomerOrganiza> wrapper = new QueryWrapper<>();
            wrapper.eq("customer_id",customerOrganiza.getCustomerId());
            wrapper.eq("departa",i);
            List<CustomerOrganiza> list = customerOrganizaMapper.selectList(wrapper);
            hashMap.put(""+i+"",list);
        }

//        //查询高层部门
//        QueryWrapper<CustomerOrganiza> wrapper1 = new QueryWrapper<>();
//        wrapper1.eq("customer_id",customerOrganiza.getCustomerId());
//        wrapper1.eq("departa",1);
//        List<CustomerOrganiza> list1 = customerOrganizaMapper.selectList(wrapper1);
//        //查询人力部门
//        QueryWrapper<CustomerOrganiza> wrapper2 = new QueryWrapper<>();
//        wrapper2.eq("customer_id",customerOrganiza.getCustomerId());
//        wrapper2.eq("departa",2);
//        List<CustomerOrganiza> list2 = customerOrganizaMapper.selectList(wrapper2);
//        //查询财务部门
//        QueryWrapper<CustomerOrganiza> wrapper3 = new QueryWrapper<>();
//        wrapper3.eq("customer_id",customerOrganiza.getCustomerId());
//        wrapper3.eq("departa",3);
//        List<CustomerOrganiza> list3 = customerOrganizaMapper.selectList(wrapper3);
//        //查询售前部门
//        QueryWrapper<CustomerOrganiza> wrapper4 = new QueryWrapper<>();
//        wrapper4.eq("customer_id",customerOrganiza.getCustomerId());
//        wrapper4.eq("departa",4);
//        List<CustomerOrganiza> list4 = customerOrganizaMapper.selectList(wrapper4);
//        //查询项目部门
//        QueryWrapper<CustomerOrganiza> wrapper5 = new QueryWrapper<>();
//        wrapper5.eq("customer_id",customerOrganiza.getCustomerId());
//        wrapper5.eq("departa",5);
//        List<CustomerOrganiza> list5 = customerOrganizaMapper.selectList(wrapper5);
//        //查询采购部门
//        QueryWrapper<CustomerOrganiza> wrapper6 = new QueryWrapper<>();
//        wrapper6.eq("customer_id",customerOrganiza.getCustomerId());
//        wrapper6.eq("departa",6);
//        List<CustomerOrganiza> list6 = customerOrganizaMapper.selectList(wrapper6);
//        //查询工程部门
//        QueryWrapper<CustomerOrganiza> wrapper7 = new QueryWrapper<>();
//        wrapper7.eq("customer_id",customerOrganiza.getCustomerId());
//        wrapper7.eq("departa",7);
//        List<CustomerOrganiza> list7 = customerOrganizaMapper.selectList(wrapper7);
//        //查询其他部门
//        QueryWrapper<CustomerOrganiza> wrapper8 = new QueryWrapper<>();
//        wrapper8.eq("customer_id",customerOrganiza.getCustomerId());
//        wrapper8.eq("departa",8);
//        List<CustomerOrganiza> list8 = customerOrganizaMapper.selectList(wrapper8);
//        hashMap.put("1",list1);
//        hashMap.put("2",list2);
//        hashMap.put("3",list3);
//        hashMap.put("4",list4);
//        hashMap.put("5",list5);
//        hashMap.put("6",list6);
//        hashMap.put("7",list7);
//        hashMap.put("8",list8);
        return hashMap;
    }


}
